package it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.Element;


public class FMouseDownListener {
    public FMouseDownListener(Element e, FMouseDownHandler handler) {
        attachMouseDownHandler(e, handler);
    }

    public static void setMouseDownEvent(Element e, FMouseDownHandler handler) {
        new FMouseDownListener(e, handler);
    }

    private static native void dispatchMouseDownHendler(JavaScriptObject event, FMouseDownHandler handler) /*-{
    
          if (!event) event = $wnd.event;

           var x = event.clientX;
            var y = event.clientY;

            handler.@it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FMouseDownHandler::onMouseDown(II)(x,y);

            if (event.preventDefault)
                     event.preventDefault();
                 event.returnValue = false;
      }-*/;

    private native void attachMouseDownHandler(Element e, FMouseDownHandler handler) /*-{

         e.onmousedown = handler;

               if ($wnd.addEventListener && !$wnd.opera) {
                   e.addEventListener('onmousedown', @it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FMouseDownListener::dispatchMouseDownHendler(Lcom/google/gwt/core/client/JavaScriptObject;Lit/fuzzylogics/fuzzywidgetsLibrary/client/FuzzyListeners/FMouseDownHandler;), false);
               }

          e.onmousedown = function(event) {

                   @it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FMouseDownListener::dispatchMouseDownHendler(Lcom/google/gwt/core/client/JavaScriptObject;Lit/fuzzylogics/fuzzywidgetsLibrary/client/FuzzyListeners/FMouseDownHandler;)(event,handler);

          }

      }-*/;
}
